package com.neuedu.yyzx.config;

import com.neuedu.yyzx.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
// @EnableWebMvc
public class WebConfig implements WebMvcConfigurer {

    @Autowired
    private LoginInterceptor loginInterceptor;



    /**
     * 设置允许跨域
     * @param registry
     */
    @Override
    public void addCorsMappings(CorsRegistry registry) {

        registry.addMapping("/*/**")
            .allowedOrigins("*")
            .allowedMethods("*")
            .maxAge(3600);

        // Add more mappings...
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {


        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")  //大部分是需要 拦截
                .excludePathPatterns("/login",
                        "/*.html", "/**/*.html", "/**/*.css", "/**/*.js", "/profile/**","/v3/api-docs/*",
                        "/swagger-ui.html", "/swagger-resources/**", "/webjars/**", "/*/api-docs/*"
                        ); //例外的
    }
}